package authorized

import (
	"gitee.com/yangguoliang001/go-gin-vue3/services/authorizedService"
	"github.com/gin-gonic/gin"
	"github.com/go-redis/redis/v7"
	"gorm.io/gorm"

	"go.uber.org/zap"
)

type Controller interface {
	QueryAuthList(c *gin.Context)
	AddAuthorized(c *gin.Context)
	UpdateAuthorized(c *gin.Context)
	DeleteAuthorized(c *gin.Context)

	QueryAuthApiList(c *gin.Context)
	AddAuthorizedApi(c *gin.Context)
	DeleteAuthorizedApi(c *gin.Context)
}

type authorizedController struct {
	logger            *zap.Logger
	cache             *redis.Client
	authorizedService authorizedService.AuthorizedService
}

func New(logger *zap.Logger, db *gorm.DB, cache *redis.Client) Controller {
	return &authorizedController{
		logger:            logger,
		cache:             cache,
		authorizedService: authorizedService.New(db, cache, logger),
	}
}
